export default class MoveParent extends godot.Sprite {
    x = 200
    y = 200
    v = 3

    isInput = false;
    isKeyMove = false;
    isMouseMove = false;

     // 物理帧 严格的60hz(1s执行60次) 事件处理 位置相关
     _physics_process(delta: number): void {
        if (this.isKeyMove) {
            // this.handleKey()
            this.handlekAction()
        }

        if (this.isMouseMove) {
            if (godot.Input.is_mouse_button_pressed(godot.BUTTON_LEFT)) {
                let mousePos = this.get_viewport().get_mouse_position()
                this.x = mousePos.x
                this.y = mousePos.y
                this.position = mousePos
            }
        }

    }

    handleKey() {
        let face = -1
        // InputAction
        if (godot.Input.is_key_pressed(godot.KEY_W)) {
            face = 3
            this.y = this.y - this.v
        } else if (godot.Input.is_key_pressed(godot.KEY_A)) {

            face = 1
            this.x = this.x - this.v
        } else if (godot.Input.is_key_pressed(godot.KEY_S)) {

            face = 0
            this.y = this.y + this.v
        } else if (godot.Input.is_key_pressed(godot.KEY_D)) {
            face = 2
            this.x = this.x + this.v
        }
        this.position = new godot.Vector2(this.x, this.y)

    }

    handlekAction() {
        let face = -1
        // InputAction
        if (godot.Input.is_action_pressed("ui_up")) {
            face = 3
            this.y = this.y - this.v
        } else if (godot.Input.is_action_pressed("ui_left")) {
            face = 1
            this.x = this.x - this.v
        } else if (godot.Input.is_action_pressed("ui_down")) {
            face = 0
            this.y = this.y + this.v
        } else if (godot.Input.is_action_pressed("ui_right")) {
            face = 2
            this.x = this.x + this.v
        }
        this.position = new godot.Vector2(this.x, this.y)
    }
}